var qn = require('qn');
let accessKey = 'Jt_e-lkljnoDelPhx0XSqo9906RvGqXzmACCQ_L6';
let secretKey = 'dzDLZ5-qiTj855maNZeB7vHAfaKbQpNbd4HdEhXJ';
var client = qn.create({
    accessKey: accessKey,
    secretKey: secretKey,
    bucket: 'wongnai',
    origin: 'http://{bucket}.u.qiniudn.com',
    // timeout: 3600000, // default rpc timeout: one hour, optional
    // if your app outside of China, please set `uploadURL` to `http://up.qiniug.com/`
    // uploadURL: 'http://up.qiniu.com/',
});

var token = client.uploadToken();

var timer = setInterval(() => {
        client.list('/', (err, result) => {
            if (err) {
                console.log(err)
                return
            }
            if (result.items.length > 0) {
                result.items.map(item => {
                    client.delete(item.key, err => {
                        if (err) {
                            console.log(err)
                        }
                    });
                })
            } else {
                timer = clearInterval(timer)
                console.log('清理完毕')
            }

        });
    },
    3000
)